﻿namespace SpaceshipDuel
{
    // simple timer class which checks if set timespan has elapsed
    public class WaitTimer
    {
        private double fElapseTime;
        private double fTimeSinceLastCheck;

        /// <summary>
        /// Konstruktor
        /// </summary>
        /// <param name="fElapseTime">total seconds of elapsed game time</param>
        public WaitTimer(double fElapseTime)
        {
            this.fElapseTime = fElapseTime;
            fTimeSinceLastCheck = 0.0f;
        }

        /// <summary>
        /// check is times is elapsed
        /// </summary>
        /// <param name="fGameTime">total seconds of elapsed gametime</param>
        /// <returns>true, if timer is elapsed</returns>
        public bool IsElapsed(double fGameTime)
        {
            fTimeSinceLastCheck += fGameTime;

            if (fTimeSinceLastCheck >= fElapseTime)
            {
                fTimeSinceLastCheck = 0.0f;
                return true;
            }
            else
                return false;
        }

        /// <summary>
        /// Resets the timer
        /// </summary>
        public void Reset()
        {
            fTimeSinceLastCheck = 0.0f;
        }

        public double GetTimeSinceLastCheck()
        {
            return fTimeSinceLastCheck;
        }

    }
}
